package controller

import (
	"ahutoj/web/dao"
	mysqldao "ahutoj/web/dao/mysqlDao"
	"ahutoj/web/io/constanct"
	"ahutoj/web/io/request"
	"ahutoj/web/io/response"
	"ahutoj/web/logic"
	"ahutoj/web/middlewares"
	"ahutoj/web/models"
	"ahutoj/web/utils"

	"github.com/gin-gonic/gin/binding"
	"strconv"
	"github.com/gin-gonic/gin"
)

//总结，标签，参数，请求体，响应体，路由

// @Summary	用户信息
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Param		UID	query		string	false	"-"
// @Success	200	{object}	response.UserResp
// @Router		/api/user/info [get]
func UserInfo(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := ctx.Query("UID")
	if req == "" {
		req = middlewares.GetUid(ctx)
	}
	// logger.Infof("req:%+v", req)
	resp, err := logic.GetUserInfo(ctx, &req)
	if err != nil {
		logger.Errorf("call GetUserInfo failed,req=%+v,err=%s", req, err.Error())
		response.ResponseError(ctx, constanct.ServerErrorCode)
	}
	response.ResponseOK(ctx, resp)
}

// @Summary	获取用户在线列表
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Success	200					{object}	response.UserStatusListResp
// @Router		/api/user/status/list [get]
func UserStausList(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.GetListReq)
	if err := ctx.ShouldBindWith(req, binding.Query); err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.GetUserStatusList(ctx, req)
	if err != nil {
		logger.Errorf("call GetUserStatusList failed,err=%s", err.Error())
		response.ResponseError(ctx, constanct.ServerErrorCode)
	}
	response.ResponseOK(ctx, resp)
}

// @Summary	获取用户在线列表
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Param		GetUserSolutionListReq	query		request.GetUserSolutionListReq	true	"-"
// @Success	200					{object}	response.GetUserSolutionListResp
// @Router		/api/user/solution/list [get]
func UserSolutionList(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.GetUserSolutionListReq)
	if err := ctx.ShouldBindWith(req, binding.Query); err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.GetUserSolutionList(ctx, req)
	if err != nil {
		logger.Errorf("call GetUserSolutionList failed,err=%s", err.Error())
		response.ResponseError(ctx, constanct.ServerErrorCode)
	}
	response.ResponseOK(ctx, resp)
}

// @Summary	用户提交信息
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Param		UserStatusInfoReq	body		request.UserStatusInfoReq	true	"-"
// @Success	200					{object}	response.UserStatusInfoResp
// @Router		/api/user/info/status/ [post]
func UserStatusInfo(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.UserStatusInfoReq)
	if err := ctx.ShouldBindBodyWith(req, binding.JSON); err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}

	resp, err := logic.GetUserStatusInfo(ctx, *req)
	if err != nil {
		logger.Errorf("call GetUserStatusInfo failed, req=%+v, err=%s", utils.Sdump(req), err.Error())
		response.ResponseError(ctx, constanct.ServerErrorCode)
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary	编辑用户信息
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Param		UserEditReq	body		request.UserEditReq	true	"-"
// @Success	200			{object}	response.Response
// @Router		/api/user/edit/ [post]
func EditUserInfo(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := &request.UserEditReq{}
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseOK(ctx, constanct.InvalidParamCode)
		return
	}
	usr := req.ToUser(middlewares.GetUid(ctx))

	// call db
	if !models.IsUserExistByUID(ctx, usr) {
		response.ResponseOK(ctx, constanct.USER_EDITINFO_UIDNotExistCode)
		return
	}

	// erase illegal data
	{
		usr.Pass = ""
		usr.Vjid = ""
	}

	err = mysqldao.UpdateUserByUID(ctx, usr)
	if err != nil {
		logger.Errorf("update user info failed, err = %s", err.Error())
		response.ResponseOK(ctx, constanct.USER_CFBIND_FAILED)
		return
	}

	response.ResponseOK(ctx, response.CreateResponse(constanct.SuccessCode))
}

// @Summary	修改密码
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Param		UserEditPassReq	body		request.UserEditPassReq	true	"-"
// @Success	200				{object}	response.Response
// @Router		/api/user/edit/pass/ [post]
func EditUserPass(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := &request.UserEditPassReq{}
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	// call db
	usr := &dao.User{
		UID: middlewares.GetUid(ctx),
	}
	err = mysqldao.SelectUserByUID(ctx, usr)
	if err != nil {
		logger.Errorf("query user failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.USER_EDITPASS_FAILED)
		return
	}

	if !models.EqualPassWord(ctx, usr, req.OldPwd) {
		logger.Info("user old_pwd error!!")
		response.ResponseError(ctx, constanct.USER_EDITPASS_PasswordCode)
		return
	}
	if req.Pwd == "" {
		response.ResponseError(ctx, constanct.USER_EDITPASS_PasswordEmptyCode)
		return
	}
	usr.Pass, _ = utils.MD5EnCode(usr.UID, req.Pwd)

	err = mysqldao.UpdateUserByUID(ctx, usr)
	if err != nil {
		logger.Errorf("update user passwd failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.USER_EDITPASS_FAILED)
		return
	}
	response.ResponseOK(ctx, response.CreateResponse(constanct.SuccessCode))
}

// @Summary	用户绑定Vjudge
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Param		CodeVerifyReq	body		request.CodeVerifyReq	true	"-"
// @Success	200				{object}	response.Response
// @Router		/api/user/vjudgeBind [post]
func VjudgeBind(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := &request.UserEditVjudgeReq{}
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}

	usr := req.ToUser(middlewares.GetUid(ctx))
	// usr.Vjpwd, _ = utils.MD5EnCode(req.Vjid, req.Vjpwd)

	// call db
	err = mysqldao.UpdateUserByUID(ctx, usr)
	if err != nil {
		logger.Errorf("update mysql error =%s", err.Error())
		response.ResponseError(ctx, constanct.ServerErrorCode)
		return
	}
	response.ResponseOK(ctx, response.CreateResponse(constanct.SuccessCode))
}

// @Summary cf绑定
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Param		CodeForceBindReq	body		request.CodeForceBindReq	true	"-"
// @Success	200					{object}	response.Response
// @Router		/api/user/codeforceBind/ [post]
func CodeForceBind(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.CodeForceBindReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.CodeForceBind(ctx, *req)
	if err != nil {
		logger.Errorf("call CodeForceBind err=%s, req=%+v", err.Error(), utils.Sdump(req))
		response.ResponseError(ctx, resp.(constanct.ResCode))
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary Atcoder绑定
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Param		CodeForceBindReq	body		request.CodeForceBindReq	true	"-"
// @Success	200					{object}	response.Response
// @Router		/api/user/atcoderBind/ [post]
func AtcoderBind(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.AtcoderBindReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	// logger.Debugf("call AtcoderBind resp=%+v", req)
	resp, err := logic.AtcoderBind(ctx, req)
	if err != nil {
		logger.Errorf("call CodeForceBind err=%s, req=%+v", err.Error(), utils.Sdump(req))
		response.ResponseError(ctx, constanct.ServerErrorCode)
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary 牛客绑定
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Param		CodeForceBindReq	body		request.CodeForceBindReq	true	"-"
// @Success	200					{object}	response.Response
// @Router		/api/user/nowcoderBind/ [post]
func NowcoderBind(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.NowcoderBindReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.NowcoderBind(ctx, req)
	if err != nil {
		logger.Errorf("call CodeForceBind err=%s, req=%+v", err.Error(), utils.Sdump(req))
		response.ResponseError(ctx, constanct.ServerErrorCode)
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Param		UserEditHeadImageReq	body		request.UserEditHeadImageReq	true	"-"
// @Success	200		{object}	response.EditHeadImageResp
// @Router		/api/user/editHead/ [post]
func EditImage(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.UserEditHeadImageReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith filed, err=%s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	//更新用户信息
	user := dao.User{
		UID:     middlewares.GetUid(ctx),
		HeadURL: req.HeadPath,
	}
	err = mysqldao.UpdateUserByUID(ctx, &user)
	if err != nil {
		logger.Errorf("update Image Failed,err:%v", err.Error())
		response.ResponseError(ctx, constanct.ServerErrorCode)
		return
	}
	response.ResponseOK(ctx, response.EditHeadImageResp{
		Response: response.CreateResponse(constanct.SuccessCode),
		ImageURL: user.HeadURL,
	},
	)
}

// @Summary	找回密码
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Param		PasswordForgetReq	body		request.PasswordForgetReq	true	"-"
// @Success	200					{object}	response.Response
// @Router		/api/user/forget/pass/ [post]
func PasswordForget(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.PasswordForgetReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.PasswordForget(ctx, req)
	if err != nil {
		logger.Errorf("call CodeForceBind err=%s, req=%+v", err.Error(), utils.Sdump(req))
		response.ResponseError(ctx, resp.(constanct.ResCode))
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary	用户在线状态检测
// @Description
// @Tags		User
// @Accept		json
// @Produce	json
// @Success	200					{object}	[]byte{}
// @Router		/ws [get]
func CreateWsClient(ctx *gin.Context) {
	// UID := middlewares.GetUid(ctx)
	logger := utils.GetLogInstance()
	token := ctx.Query("token")
	if token == "" {
		logger.Error("token is empty")
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	claims, err := middlewares.ParseToken(token)
	if err != nil {
		logger.Errorf("parse token failed, err=%s", err.Error())
		response.ResponseError(ctx, constanct.AUTH_Token_InvalidCode)
		return
	}
	err = middlewares.WsHandlerConn(ctx.Writer, ctx.Request, claims.UserID)
	if err != nil {
		response.ResponseError(ctx, constanct.ServerErrorCode)
		return
	}
}

// @Summary 添加组
// @Description 添加一个新的组
// @Tags User
// @Accept json
// @Produce json
// @Param AddGroupReq body request.AddGroupReq true "-"
// @Success 200 {object} response.AddGroupResp
// @Router /api/user/group/add/ [post]
func AddGroup(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.AddGroupReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.AddGroup(ctx, req)
	if err != nil {
		logger.Errorf("call AddGroup err=%s, req=%+v", err.Error(), utils.Sdump(req))
		response.ResponseError(ctx, resp.(constanct.ResCode))//这里想重写一下，应该在ResponseError内部尝试转换，如果失败或者一个没有的Msg，则返回ServerErrorCode
		//好处是对于返回前端的都是设计好的错误，后端logic层也可以返回nil，而打印出内部错误，不需要麻烦的定义一个新的错误码，当然也可以传ServerErrorCode，会显得多此一举
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary 删除组
// @Description 删除一个组
// @Tags User
// @Accept json
// @Produce json
// @Param DeleteGroupReq body request.DeleteGroupReq true "-"
// @Success 200 {object} response.Response
// @Router /api/user/group/delete/ [post]
func DeleteGroup(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.DeleteGroupReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.DeleteGroup(ctx, req)
	if err != nil {
		logger.Errorf("call DeleteGroup err=%s, req=%+v", err.Error(), utils.Sdump(req))
		response.ResponseError(ctx, resp.(constanct.ResCode))
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary 编辑组
// @Description 编辑一个组的信息，包括组任务、CID、PID、LID
// @Tags User
// @Accept json
// @Produce json
// @Param EditGroupReq body request.EditGroupReq true "-"
// @Success 200 {object} response.Response
// @Router /api/user/group/edit/ [post]
func EditGroup(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.EditGroupReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.EditGroup(ctx, req)
	if err != nil {
		logger.Errorf("call EditGroup err=%s, req=%+v", err.Error(), utils.Sdump(req))
		response.ResponseError(ctx, resp.(constanct.ResCode))
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary 获取组列表
// @Description 获取所有组的列表
// @Tags User
// @Accept json
// @Produce json
// @Param GetListReq body request.GetListReq true "-"
// @Success 200 {object} response.GetGroupListResp
// @Router /api/user/group/list/ [post]
func GetGroupList(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.GetListReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.GetGroupList(ctx,req)
	if err != nil {
		logger.Errorf("call GetGroupList err=%s", err.Error())
		response.ResponseError(ctx, resp.(constanct.ResCode))
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary 获取组信息
// @Description 获取指定组的信息
// @Tags User
// @Accept json
// @Produce json
// @Param id path int true "Group ID"
// @Success 200 {object} response.GetGroupResp
// @Router /api/user/group/{id} [get]
func GetGroup(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	GIDstr := ctx.Param("id")
	GID, err := strconv.ParseInt(GIDstr, 10, 64)
	if err != nil {
		logger.Errorf("call ParseInt failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.GetGroup(ctx, GID)
	if err != nil {
		logger.Errorf("call GetGroup err=%s, groupID=%s", err.Error(), GIDstr)
		response.ResponseError(ctx, resp.(constanct.ResCode))
		return
	}
	response.ResponseOK(ctx, resp)
}


// @Summary 转让群组
// @Description 主动转让或在组长想要退出时显示
// @Tags User
// @Accept json
// @Produce json
// @Param GroupTransferReq body request.GroupTransferReq true "-"
// @Success 200 {object} response.Response
// @Router /api/user/group/trans/ [post]
func GroupTransfer(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.GroupTransferReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.GroupTransfer(ctx, req)
	if err != nil {
		logger.Errorf("call GetGroupList err=%s", err.Error())
		response.ResponseError(ctx, resp.(constanct.ResCode))
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary 添加用户到组
// @Description 将用户添加到指定组
// @Tags User
// @Accept json
// @Produce json
// @Param AddUserToGroupReq body request.AddUserToGroupReq true "-"
// @Success 200 {object} response.Response
// @Router /api/user/group/user/add/ [post]
func AddUserToGroup(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.AddUserToGroupReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.AddUserToGroup(ctx, req)
	if err != nil {
		logger.Errorf("call AddUserToGroup err=%s, req=%+v", err.Error(), utils.Sdump(req))
		response.ResponseError(ctx, resp.(constanct.ResCode))
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary 从组中删除用户
// @Description 从指定组中删除用户
// @Tags User
// @Accept json
// @Produce json
// @Param DeleteUserFromGroupReq body request.DeleteUserFromGroupReq true "-"
// @Success 200 {object} response.Response
// @Router /api/user/group/user/delete/ [post]
func DeleteUserFromGroup(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.DeleteUserFromGroupReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.DeleteUserFromGroup(ctx, req)
	if err != nil {
		logger.Errorf("call DeleteUserFromGroup err=%s, req=%+v", err.Error(), utils.Sdump(req))
		response.ResponseError(ctx, resp.(constanct.ResCode))
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary 加入组
// @Description 用户加入指定组
// @Tags User
// @Accept json
// @Produce json
// @Param JoinGroupReq body request.JoinGroupReq true "-"
// @Success 200 {object} response.JoinGroupResp
// @Router /api/user/group/join/ [post]
func JoinGroup(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.JoinGroupReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.JoinGroup(ctx, req)
	if err != nil {
		logger.Errorf("call JoinGroup err=%s, req=%+v", err.Error(), utils.Sdump(req))
		response.ResponseError(ctx, constanct.USER_GROUP_USER_JOIN_FAILED)
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary 退出组,如果是组长，需要先移交
// @Description 用户退出指定组
// @Tags User
// @Accept json
// @Produce json
// @Param QuitGroupReq body request.QuitGroupReq true "-"
// @Success 200 {object} response.QuitGroupResp
// @Router /api/user/group/quit/ [post]
func QuitGroup(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req := new(request.QuitGroupReq)
	err := ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.QuitGroup(ctx, req)
	if err != nil {
		logger.Errorf("call QuitGroup err=%s, req=%+v", err.Error(), utils.Sdump(req))
		response.ResponseError(ctx, resp.(constanct.ResCode))
		return
	}
	response.ResponseOK(ctx, resp)
}

// @Summary 获取用户或组的Trace
// @Description 
// @Tags User
// @Accept json
// @Produce json
// @Param GID query string true "GID"
// @Success 200 {object} response.GetGroupTraceResp
// @Router /api/user/group/trace/ [post]
func GetGroupTrace(ctx *gin.Context) {
	logger := utils.GetLogInstance()
	req:=new(request.GetGroupTraceReq)
	var err error
	err = ctx.ShouldBindWith(req, binding.JSON)
	if err != nil {
		logger.Errorf("call ShouldBindWith failed, err = %s", err.Error())
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	gid:=ctx.Query("GID")
	if gid!=""{
		req.GID,err= strconv.ParseInt(gid,10,64)
		if err!=nil{
			logger.Errorf("call ParseInt failed, err = %s", err.Error())
			response.ResponseError(ctx, constanct.ServerErrorCode)
			return
		}
	}else{
		response.ResponseError(ctx, constanct.InvalidParamCode)
		return
	}
	resp, err := logic.GetGroupTrace(ctx,req)
	if err != nil {
		logger.Errorf("call GetGroupTrace err=%s, req=%+v", err.Error(), utils.Sdump(req))
		response.ResponseError(ctx, resp.(constanct.ResCode))
		return
	}
	response.ResponseOK(ctx, resp)
}